<?php if (!defined("_ECRIRE_INC_VERSION")) return;

/**
 *  Dymanic Tag which outputs option filter's results.
 *  The idea is that it passes result array of articles IDs (#ARTICLES_IDS) in template,
 *  and you use this array in there to get filtered articles.
 *  It provides default html template, but in most cases you will override it in squelettes or
 *  by passing parameter. Example:
 *      #ECATALOGUE_OPTION_FILTER_RESULT{inc/filter_result_template_file}
 */

function balise_ECATALOGUE_OPTION_FILTER_RESULT($p) {	
	return calculer_balise_dynamique($p,'ECATALOGUE_OPTION_FILTER_RESULT', array());
}

function balise_ECATALOGUE_OPTION_FILTER_RESULT_stat($args, $filtres) {    
	return $args;
}

function balise_ECATALOGUE_OPTION_FILTER_RESULT_dyn($template = 'balise/ecatalogue_option_filter_result', $params = array()) {
    include_spip('functions/pdk_url');

    $query = "SELECT A.id_article FROM spip_articles A ";

    $id_options = _request('id_option');
    $clear_options = array();
    if (!empty($id_options)) {
        foreach ($id_options as $id_option) {
            if (!$id_option == intval($id_option))
                continue;
            $clear_options[] = $id_option;
        }
    }
    $clear_options = array_unique($clear_options);

    if (!empty($clear_options)) {
        $query .= 'INNER join spip_ecatalogue_articles_options as AO ON A.id_article=AO.id_article WHERE id_option in ('
                .implode(',',$clear_options).')';
    }

    $articles_ids = sql_fetch_all(sql_query($query));
    return array($template, 0, 
		array_merge(array('articles_ids' => $articles_ids), $params)
    );
}

?>